from django.db import models

from sportsground.utils.baseModels import BaseModels


class Goods(BaseModels):
    class Meta():
        db_table = 'Venue_goods'
        verbose_name = '馆场商品'
        verbose_name_plural = verbose_name

    venue = models.ForeignKey(to="Venue.Venue", on_delete=models.CASCADE, verbose_name="对应场馆")
    name = models.CharField(max_length=50, verbose_name="商品名称")
    type = models.ForeignKey(to="GoodsType", null=True, on_delete=models.SET_NULL, verbose_name="类型")
    price = models.FloatField(verbose_name="价格")
    detail = models.CharField(max_length=200, verbose_name="描述")

    @classmethod
    def create(cls, venue, name, type, price, detail=''):
        """ 创建 """
        goods = cls(venue=venue, name=name, type=type, price=price, detail=detail)
        goods.save()
        return goods

    def Info(self):
        return {
            "id": self.id,
            "name": self.name,
            "type": self.type.Info(),
            "price": self.price,
            "detail": self.detail,
        }

    # def Details(self):
    #     """ """
